home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!austern
- From: David Olsen <olsen@rational.com>
- Newsgroups: comp.std.c++
- Subject: Comparison operators and enums
- Date: 22 Feb 1996 15:20:51 PST
- Organization: -
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <9602222305.AA03051@picard.rational.com>
- NNTP-Posting-Host: isolde.mti.sgi.com
- Content-Type: text/plain; charset="us-ascii"
- X-Original-Date: Thu, 22 Feb 1996 15:05:08 -0800
- X-Mailer: exmh version 1.5.3 12/28/94
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMSz6/Uy4NqrwXLNJAQGp9AIAtIhEy0FD2nUlnbDH4UoOOiYF1UY0kQEJ
- t8T+XgSOf/DSwosC3Ucj09pcFB+utgJwDy+E2qKFwNG4a78uR2iYqw==
- =seif
- Originator: austern@isolde.mti.sgi.com
-
- Consider the following snippet of code (which actually does arise in
- real code since the given template operator!= is taken directly from
- <utility>):
-
- template <class T>
- bool operator != (const T &x, const T &y)
- {
- return !(x == y);
- }
-
- enum E { a, b, c };
-
- bool f (const E &e1, const E &e2)
- {
- return e1 != e2;
- }
-
-
- How should the compiler interpret "e1 != e2" ? Should it instantiate
- the template function "operator!=(const E &, const E &)", or should it
- promote x and y to int and use the built-in "operator!=(int, int)" ?
-
- As I interpret the first paragraph of 13.3.3 in the April 95 draft, the
- template function is a better match because each of its arguments are
- an exact match, while the built-in operator requires a promotion for
- each argument. Is this interpretation correct? If so, is this the
- intention of the committee?
-
- --
- David Olsen
- olsen@rational.com
- ---
- [ To submit articles: Try just posting with your newsreader. If that fails,
- use mailto:std-c++@ncar.ucar.edu
- FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
- Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-